<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>项目请假单</title>
    <jsp:include page="../../../main/mp/inc.jsp"	/>
    <script>
        $(function(){
            $("[data-role='navbar']").navbar();
            $("[data-role='header'], [data-role='footer']").toolbar();
        });

        $(function(){
            var currYear = (new Date()).getFullYear();
            var opt={};
            opt.date = {preset : 'date'};
            opt.datetime = {preset : 'datetime'};
            opt.time = {preset : 'time'};
            opt.default = {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                animate:'swing',
                lang:'zh',
                startYear:currYear - 10, //开始年份
                endYear:currYear + 10 //结束年份
            };
            var optDateTime = $.extend(opt['datetime'], opt['default']);
            $("#leaveDate").val('<s:date name="proLeave.leaveDate" format="yyyy-MM-dd" />').scroller('destroy').scroller($.extend(opt['date'], opt['default']));

            $("#btn-save-proleave").click(function(e){

                if($("#leaveDate").val()==""){
                    alert("请选择请假日期！");
                    return;
                }
                if($("#reason").val()==""){
                    alert("请输入请假事由！");
                    return;
                }
                save_from();
            });

            function save_from(){
                 myConfirm("系统提示","确定提交反馈吗?",function(){
                        if($("#confirmResult").val()==="1"){
                            $("#btn-save-proleave").hide();
                            $.mobile.loading( "show", {
                                text: "正在保存，请稍后...",
                                textVisible: true,
                                theme: "b",
                                textonly: false,
                                html: ""
                            });
                            $.ajax({
                                type: "POST",
                                url: $("form#form-common").attr("action"),
                                cache:false,dataType:"json",
                                data: $("form#form-common").serialize(),
                                async:true,
                                success: function(data){
                                    if(data.state == "200"){
                                        alert(data.message);
                                        location.replace("ajax!proSignin.action");
                                    }else{
                                        $("#btn-save-proleave").show();
                                        alert(data.message);
                                    }
                                }
                            });
                        }
                 });
            }
        });
 function myConfirm(t, c, fn) {
            $("#popupConfirm h1").html(t);
            $("#popupConfirm p").html(c);
            $("#popupConfirm a:contains('是')").unbind("click").click(function() {$("#confirmResult").val("1"); $("#popupConfirm").popup("close"); });
            $("#popupConfirm a:contains('否')").unbind("click").click(function() {$("#confirmResult").val("0"); $("#popupConfirm").popup("close"); });
            if (fn) $("#popupConfirm").unbind("popupafterclose").bind("popupafterclose", function() { fn(); });
            $("#popupConfirm").popup("open");
        }
    </script>
</head>
<body>
<!-- class="jqm-demos" -->
<div data-role="page" >
    <div data-role="header" data-position="fixed" data-theme="a">
        <h1 style="float:left;margin: 0 10px;"><i class="fa fa-user"></i> 项目请假单</h1>
        <a href="#" id="btn-save-proleave" class="ui-btn ui-btn-right ui-icon-check ui-corner-all ui-btn-icon-left">保存</a>
    </div><!-- /header -->
    <div class="ui-content jqm-content jqm-fullwidth" role="main">
        <form id="form-common" method="post" action="ajax-proleave!save.action" data-ajax="false">
            <input type="hidden" name="keyId" id="keyId" value="<s:property value="proLeave.id" />"/>

            <div class="ui-field-contain">
                <label>项目名称：</label>
                <span><s:property value="proLeave.proInfo.name"/></span>
                <input type="hidden" id="proInfoId" name="proInfoId" value="<s:property value="proInfoId"/>"/>
            </div>

            <div class="ui-field-contain">
                <label>请假日期：</label>
                <span><input type="date" id="leaveDate" name="leaveDate" value="<s:property value="proLeave.leaveDate"/> " /></span>
            </div>
            <div class="ui-field-contain">
                <label>请假事由：</label>
                <span><input type="text" id="reason" name="reason" value="<s:property value="proLeave.reason"/>"></span>
            </div>

        </form>
        <input type="hidden" id="confirmResult" value="0"/>
        <div data-role="popup" id="popupConfirm" data-inline="true" data-position-to="window"
             data-theme="a" style="max-width:400px;" class="ui-corner-all">
            <div data-role="header" data-theme="b" class="ui-corner-top">
                <h1></h1>
            </div>
            <div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
                <p style="width:350px;"></p>
                <div style="text-align: center">
                    <a href="#" data-role="button" data-mini="true" data-inline="true" data-transition="flow" data-theme="c">是</a>
                    <a href="#" data-role="button" data-mini="true" data-inline="true" data-transition="flow" data-theme="c">否</a>
                </div>
            </div>
        </div>
    </div><!-- /content -->
</div><!-- /page -->

</body>
</html>